package com.example.xiaoshuo_yudu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.xiaoshuo_yudu.entity.Result;
import com.example.xiaoshuo_yudu.entity.ResultCode;
import com.example.xiaoshuo_yudu.entity.entity.Books;
import com.example.xiaoshuo_yudu.service.BooksService;
import io.swagger.v3.oas.models.security.SecurityScheme;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 小说基本信息表 前端控制器
 * </p>
 *
 * @author xusen
 * @since 2025-07-24
 */
@RestController
@RequestMapping("/api/books")
public class BooksController {
    @Autowired
    private BooksService booksService;
    /**
     * 返回前端text数组数据，包含各类榜单
     * @return
     */

    @GetMapping("/rank")
    public Result<List<Object>> rank() {
        List<Object> list = booksService.rank();
        return Result.success(list);
    }

    /**
     * 获取推荐书籍列表
     * @return
     */
    @GetMapping("/recommend-all")
    public Result<List<Object>> getBooks() {
        List<Object> list = booksService.getRecommendAll();
        return Result.success(list);
    }
    /**
     * 获取男生频道书籍列表
     */
    @GetMapping("channel/boy")
    public Result<List<Object>> getBoyChannelBooks() {
        List<Object> list = booksService.getBoyChannelBooks();
        return Result.success(list);
    }
    /**
     * 获取女生频道书籍列表
     */
    @GetMapping("channel/girl")
    public Result<List<Object>> getGirlChannelBooks() {
        List<Object> list = booksService.getGirlChannelBooks();
        return Result.success(list);
    }
    /**
     * 获取新人频道书籍列表
     */
    @GetMapping("channel/new")
    public Result<List<Object>> getNewChannelBooks() {
        List<Object> list = booksService.getnewChannelBooks();
        return Result.success(list);
    }


    /**
     * 获取小说名字和简介
     * @return
     */
    @GetMapping("nameandintro")
    public Result<List<Map<String, Object>>> getNameAndIntro() {
        List<Map<String, Object>> list = booksService.getNameAndIntro();
        return Result.success(list);
    }
    /**
     * 单本书的详细信息
     * @param bookId
     * @return
     */
    @GetMapping("listdetail")
    public Result<Map<String, String>> listDetail( @RequestParam @NotNull Integer bookId) {
        if(bookId == null)
            return Result.failure(ResultCode.NOT_FOUND);
        Map<String, String> list = booksService.getListDetail(bookId);
        return Result.success(list);
    }
    /**
     * 获取小说列表
     */
    @GetMapping("list")
    public Result<List<Map<String, Object>>> getChapterListByBookId(@RequestParam @NotNull Integer bookId ) {
        List<Map<String, Object>> list = booksService.getChapterListByBookId(bookId);
        return Result.success(list);
    }
    /*
    获取小说章节详情
     */
    @GetMapping("/{bookId}/chapters/{chapterId}")
    public Result<Map<String, Object>> getChapterDetail(@PathVariable @NotNull Integer bookId, @PathVariable @NotNull Integer chapterId) {
        Map<String, Object> map =booksService.getChapterDetail(bookId, chapterId);
        return Result.success(map);
    }

    /***
     *获取各小说页主页头
     */
    @GetMapping("/{Name}/list")
    public Result<List<Map<String, Object>>> getBooksList(@PathVariable String Name) {

        List<Map<String, Object>> list = booksService.getBooksList(Name);
        return Result.success(list);
    }

    /***
     *获取各小说页主页下右
     */
    @GetMapping("/{Name}/noveldata")
    public Result<List<Map<String, Object>>> getBooksDataList(@PathVariable String Name) {

        List<Map<String, Object>> list = booksService.getBooksDataList(Name);
        return Result.success(list);
    }

    /***
     *获取各小说页主页下左
     */
    @GetMapping("/{Name}/data")
    public Result<List<Map<String, Object>>> getBooksData(@PathVariable String Name) {
        List<Map<String, Object>> list = booksService.getBooksData(Name);
        return Result.success(list);
    }
    @GetMapping("/search")
    public Result<List<Map<String, Object>>> search(@RequestParam String keyword) {
        List<Map<String, Object>> list = booksService.searchBookByKayword(keyword);
        return Result.success(list);
    }
    @GetMapping("/categories")
    public Result<String> getCategories(@RequestParam @NotNull Long bookId ) {

        String list = booksService.getCategories(bookId);
        return Result.success(list);
    }
}
